package com.tee.live.im.core.server.common;

import io.netty.channel.ChannelHandlerContext;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ChannelHandlerContextCache {

    private static Map<Long, ChannelHandlerContext> channelHandlerContextMap = new ConcurrentHashMap<Long, ChannelHandlerContext>();

    /**
     * 当前的im服务启动的时候,对外暴漏的ip和端口
     */
    private static String SERVER_IP_ADDRESS = "";

    public static String getServerIpAddress() {
        return SERVER_IP_ADDRESS;
    }

    public static void setServerIpAddress(String serverIpAddress) {
        SERVER_IP_ADDRESS = serverIpAddress;
    }

    /**
     * 缓存channelHandlerContext
     * @param userId
     * @param channelHandlerContext
     */
    public static void put(Long userId, ChannelHandlerContext channelHandlerContext) {
        channelHandlerContextMap.put(userId, channelHandlerContext);
    }

     /**
      * 获取channelHandlerContext
      * @param userId
      * @return
      */
    public static ChannelHandlerContext get(Long userId) {
        return channelHandlerContextMap.get(userId);
    }

    /**
     * 移除channelHandlerContext
     * @param userId
     */
    public static void remove(Long userId) {
        channelHandlerContextMap.remove(userId);
    }



}
